package com.lb.controller;

import com.lb.common.Result;
import com.lb.utils.SmsUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.concurrent.TimeUnit;

@Slf4j
@RestController
@CrossOrigin
@RequestMapping
public class smscontroller {
    @Autowired
    private StringRedisTemplate stringRedisTemplate;
    @GetMapping("/getCode")
       public Result getCode(@RequestParam String phone) throws Exception {

           String s = SmsUtil.sendSms(phone);
           String code= SmsUtil.sendSms(phone);
           String key="phone"+phone;
           stringRedisTemplate.opsForValue().set(key, code, 6000, TimeUnit.SECONDS);
          // stringRedisTemplate.opsForValue().set(phone, s);
           return Result.success();

       }

}
